Return to start page

Systems/Gui/Struct Widget.j

Code

		
1			library AStructSystemsGuiWidget requires ALibraryCoreInterfaceTrackable, ALibraryCoreEnvironmentSound, AStructSystemsGuiGui
2
3 /// @todo Should be a static method of @struct AWidget, vJass bug.
4 function interface AWidgetOnHitAction takes AWidget usedWidget returns nothing
5
6 /// @todo Should be a static method of @struct AWidget, vJass bug.
7 function interface AWidgetOnTrackAction takes AWidget usedWidget returns nothing
8
9 /// @todo Should be a static method of @struct AWidget, vJass bug.
10 /// Use this method as track action if you want to have the generic tooltip.
11 /// You can also use another track action and call this method in your custom action.
12 function onTrackActionShowTooltip takes AWidget usedWidget returns nothing
13 call usedWidget.mainWindow().showTooltip(usedWidget)
14 endfunction
15
16 struct AWidget
17 //static start members
18 private static string onHitSoundPath
19 private static string onTrackSoundPath
20 //dynamic members
21 private boolean m_shown
22 private integer m_shortcut //Wenn das Tastenkürzel gedrückt wird, wird auch die onHitFunction ausgeführt. Die Tastenkürzel werden über eine ausgewählte Einheit mit entsprechenden Fähigkeiten gesteuert.
23 private string m_tooltip
24 private real m_tooltipSize
25 //start members
26 private AMainWindow m_mainWindow
27 private real m_x
28 private real m_y
29 private real m_sizeX
30 private real m_sizeY
31 private AWidgetOnHitAction m_onHitAction
32 private AWidgetOnTrackAction m_onTrackAction
33 //members
34 private integer m_index
35 private trackable m_trackable
36 private trigger m_onHitTrigger
37 private trigger m_onTrackTrigger
38
39 //dynamic members
40
41 public method setShown takes boolean shown returns nothing
42 if (this.m_shown == shown) then
43 return
44 endif
45 if (shown) then
46 call this.show()
47 else
48 call this.hide()
49 endif
50 endmethod
51
52 public method isShown takes nothing returns boolean
53 return this.m_shown
54 endmethod
55
56 /// Important: Set all shortcuts when before showing the GUI.
57 /// When hiding the GUI all shortcut actions will be reseted (because of the different main windows).
58 public method setShortcut takes integer shortcut returns nothing
59 //clear old action
60 if (this.m_shortcut != 0) then
61 call this.m_mainWindow.gui().setOnPressShortcutAction(shortcut, 0, 0)
62 endif
63 set this.m_shortcut = shortcut
64 if (this.m_onHitAction != 0) then
65 call this.m_mainWindow.gui().setOnPressShortcutAction(shortcut, this.m_onHitAction, this)
66 endif
67 endmethod
68
69 public method shortcut takes nothing returns integer
70 return this.m_shortcut
71 endmethod
72
73 public method setTooltip takes string tooltip returns nothing
74 set this.m_tooltip = tooltip
75 endmethod
76
77 public method tooltip takes nothing returns string
78 return this.m_tooltip
79 endmethod
80
81 public method setTooltipSize takes real tooltipSize returns nothing
82 set this.m_tooltipSize = tooltipSize
83 endmethod
84
85 public method tooltipSize takes nothing returns real
86 return this.m_tooltipSize
87 endmethod
88
89 //start members
90
91 public method mainWindow takes nothing returns AMainWindow
92 return this.m_mainWindow
93 endmethod
94
95 public method x takes nothing returns real
96 return this.m_x
97 endmethod
98
99 public method y takes nothing returns real
100 return this.m_y
101 endmethod
102
103 public method sizeX takes nothing returns real
104 return this.m_sizeX
105 endmethod
106
107 public method sizeY takes nothing returns real
108 return this.m_sizeY
109 endmethod
110
111 //members
112
113 public method index takes nothing returns integer
114 return this.m_index
115 endmethod
116
117 //convenience methods
118
119 public method gui takes nothing returns AGui
120 return this.m_mainWindow.gui()
121 endmethod
122
123 public method user takes nothing returns player
124 return this.m_mainWindow.user()
125 endmethod
126
127 //methods
128
129 public stub method show takes nothing returns nothing
130 call this.enableOnHitTrigger()
131 call this.enableOnTrackTrigger()
132 set this.m_shown = true
133 endmethod
134
135 public stub method hide takes nothing returns nothing
136 call this.disableOnHitTrigger()
137 call this.disableOnTrackTrigger()
138 set this.m_shown = false
139 endmethod
140
141 private method enableOnHitTrigger takes nothing returns nothing
142 if (this.m_onHitAction != 0) then
143 call EnableTrigger(this.m_onHitTrigger)
144 endif
145 endmethod
146
147 private method enableOnTrackTrigger takes nothing returns nothing
148 if (this.m_onTrackAction != 0) then
149 call EnableTrigger(this.m_onTrackTrigger)
150 endif
151 endmethod
152
153 private method disableOnHitTrigger takes nothing returns nothing
154 if (this.m_onHitAction != 0) then
155 call DisableTrigger(this.m_onHitTrigger)
156 endif
157 endmethod
158
159 private method disableOnTrackTrigger takes nothing returns nothing
160 if (this.m_onTrackAction != 0) then
161 call DisableTrigger(this.m_onTrackTrigger)
162 endif
163 endmethod
164
165 private method createTrackable takes nothing returns nothing
166 if ((this.m_onHitAction != 0) or (this.m_onTrackAction != 0)) then
167 set this.m_trackable = CreateTrackableForPlayer(this.user(), thistype.getTrackablePathBySize(this.m_sizeX, this.m_sizeY), this.m_mainWindow.getX(this.m_x), this.m_mainWindow.getY(this.m_y), 0.0)
168 endif
169 endmethod
170
171 private static method triggerActionOnHit takes nothing returns nothing
172 local trigger triggeringTrigger = GetTriggeringTrigger()
173 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
174 call this.m_onHitAction.execute(this)
175 if (thistype.onHitSoundPath != null) then
176 call PlaySoundPathForPlayer(this.user(), thistype.onHitSoundPath)
177 endif
178 set triggeringTrigger = null
179 endmethod
180
181 private method createOnHitTrigger takes nothing returns nothing
182 local event triggerEvent
183 local triggeraction triggerAction
184 if (this.m_onHitAction != 0) then
185 set this.m_onHitTrigger = CreateTrigger()
186 set triggerEvent = TriggerRegisterTrackableHitEvent(this.m_onHitTrigger, this.m_trackable)
187 set triggerAction = TriggerAddAction(this.m_onHitTrigger, function thistype.triggerActionOnHit)
188 call AHashTable.global().setHandleInteger(this.m_onHitTrigger, "this", this)
189 set triggerEvent = null
190 set triggerAction = null
191 endif
192 endmethod
193
194 private static method triggerActionOnTrack takes nothing returns nothing
195 local trigger triggeringTrigger = GetTriggeringTrigger()
196 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
197 call this.m_onTrackAction.execute(this)
198 if (thistype.onTrackSoundPath != null) then
199 call PlaySoundPathForPlayer(this.user(), thistype.onTrackSoundPath)
200 endif
201 set triggeringTrigger = null
202 endmethod
203
204 private method createOnTrackTrigger takes nothing returns nothing
205 local event triggerEvent
206 local triggeraction triggerAction
207 if (this.m_onTrackAction != 0) then
208 set this.m_onTrackTrigger = CreateTrigger()
209 set triggerEvent = TriggerRegisterTrackableTrackEvent(this.m_onTrackTrigger, this.m_trackable)
210 set triggerAction = TriggerAddAction(this.m_onTrackTrigger, function thistype.triggerActionOnTrack)
211 call AHashTable.global().setHandleInteger(this.m_onTrackTrigger, "this", this)
212 set triggerEvent = null
213 set triggerAction = null
214 endif
215 endmethod
216
217 public static method create takes AMainWindow mainWindow, real x, real y, real sizeX, real sizeY, AWidgetOnHitAction onHitAction, AWidgetOnTrackAction onTrackAction returns thistype
218 local thistype this = thistype.allocate()
219 //dynamic members
220 set this.m_shown = false
221 //start members
222 set this.m_mainWindow = mainWindow
223 set this.m_x = x
224 set this.m_y = y
225 set this.m_sizeX = sizeX
226 set this.m_sizeY = sizeY
227 set this.m_onHitAction = onHitAction
228 set this.m_onTrackAction = onTrackAction
229 //members
230 set this.m_index = mainWindow.dockWidget(this)
231
232 call this.createTrackable()
233 call this.createOnHitTrigger()
234 call this.createOnTrackTrigger()
235 return this
236 endmethod
237
238 private method destroyTrackable takes nothing returns nothing
239 if ((this.m_onHitAction != 0) or (this.m_onTrackAction != 0)) then
240 //we can't destroy trackables :-[
241 set this.m_trackable = null
242 endif
243 endmethod
244
245 private method destroyOnHitTrigger takes nothing returns nothing
246 if (this.m_onHitAction != 0) then
247 call AHashTable.global().destroyTrigger(this.m_onHitTrigger)
248 set this.m_onHitTrigger = null
249 endif
250 endmethod
251
252 private method destroyOnTrackTrigger takes nothing returns nothing
253 if (this.m_onTrackAction != 0) then
254 call AHashTable.global().destroyTrigger(this.m_onTrackTrigger)
255 set this.m_onTrackTrigger = null
256 endif
257 endmethod
258
259 public method onDestroy takes nothing returns nothing
260 call this.m_mainWindow.undockWidgetByIndex(this.m_index)
261 call this.destroyOnHitTrigger()
262 call this.destroyOnTrackTrigger()
263 endmethod
264
265 public static method init takes string onHitSoundPath, string onTrackSoundPath returns nothing
266 set thistype.onHitSoundPath = onHitSoundPath
267 set thistype.onTrackSoundPath = onTrackSoundPath
268
269 if (onHitSoundPath != null) then
270 call PreloadSoundPath(onHitSoundPath)
271 endif
272 if (onTrackSoundPath != null) then
273 call PreloadSoundPath(onTrackSoundPath)
274 endif
275 endmethod
276
277 public static method getTrackablePathBySize takes real sizeX, real sizeY returns string
278 //I need a list of models, which has the specific sizes of trackables
279 return "units\\nightelf\\Wisp\\Wisp.mdx"
280 endmethod
281 endstruct
282
283 endlibrary